The Coronavirus Dashboard: the case of Bulgaria
This [Coronavirus dashboard: the case of Bulgaria] provides an overview of the Novel Coronavirus (COVID-19 / SARS-CoV-2) epidemic for Bulgaria. This dashboard is built with R using the R Makrdown and flexdashboard framework and was adapted from this dashboard by Rami Krispin.
Code
The code behind this dashboard is available on GitHub courtesy of Antoine Soetewey.
Packages
Data
The input data for this dashboard is the dataset available from the {coronavirus} R package.
The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository.
---
title: "COVID-19 in Bulgaria"
author: "Metodi Simeonov"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
#devtools::install_github("RamiKrispin/coronavirus", force = TRUE)
library(coronavirus)
data(coronavirus)
`%>%` <- magrittr::`%>%`
#------------------ Parameters ------------------
# Set colors - https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "#4682B4"
active_color <- "#1f77b4"
recovered_color <- "deepskyblue"
death_color <- "#451208"
#------------------ Data ------------------
df <- coronavirus %>%
dplyr::filter(country == "Bulgaria") %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total = sum(cases)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
dplyr::arrange(-confirmed) %>%
dplyr::ungroup() %>%
dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
dplyr::mutate(country = trimws(country)) %>%
dplyr::mutate(country = factor(country, levels = country))
df_daily <- coronavirus %>%
dplyr::filter(country == "Bulgaria") %>%
dplyr::group_by(date, type) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::arrange(date) %>%
dplyr::ungroup() %>%
dplyr::mutate(active = confirmed - death) %>%
dplyr::mutate(
confirmed_cum = cumsum(confirmed),
death_cum = cumsum(death),
active_cum = cumsum(active)
)
df1 <- coronavirus %>% dplyr::filter(date == max(date))
```
Summary Tab
=====================================
Column {data-width=400}
-----------------------------------------------------------------------
### Confirmed cases {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$confirmed), big.mark = ","), "", sep = " "),
caption = "Total Confirmed Cases",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### Deaths {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$death, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$death, na.rm = TRUE) / sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Death cases (death rate)",
icon = "fa-cross",
color = death_color
)
```
Column
-----------------------------------------------------------------------
### **Daily cumulative cases by type** (Bulgaria only)
```{r}
plotly::plot_ly(data = df_daily) %>%
plotly::add_trace(
x = ~date,
y = ~confirmed_cum,
type = "scatter",
mode = "lines+markers",
name = "Confirmed",
line = list(color = active_color),
marker = list(color = active_color)
) %>%
plotly::add_trace(
x = ~date,
y = ~death_cum,
type = "scatter",
mode = "lines+markers",
name = "Death",
line = list(color = death_color),
marker = list(color = death_color)
) %>%
plotly::add_annotations(
x = as.Date("2020-03-11"),
y = 3,
text = paste("First Death"),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -90,
ay = -90
) %>%
plotly::add_annotations(
x = as.Date("2020-03-13"),
y = 14,
text = paste(
"Lockdown"
),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -10,
ay = -90
) %>%
plotly::layout(
title = "",
yaxis = list(title = "Cumulative number of cases"),
xaxis = list(title = "Date"),
legend = list(x = 0.1, y = 0.9),
hovermode = "compare"
)
```
Comparison by Country
=====================================
Column {data-width=400}
-------------------------------------
### **Daily new confirmed cases**
```{r}
daily_confirmed <- coronavirus %>%
dplyr::filter(type == "confirmed") %>%
dplyr::filter(date >= "2020-03-07") %>%
dplyr::mutate(country = country) %>%
dplyr::group_by(date, country) %>%
dplyr::summarise(total = sum(cases)) %>%
dplyr::ungroup() %>%
tidyr::pivot_wider(names_from = country, values_from = total)
#----------------------------------------
# Plotting the data
daily_confirmed %>%
plotly::plot_ly() %>%
plotly::add_trace(
x = ~date,
y = ~Bulgaria,
type = "scatter",
mode = "lines+markers",
name = "Bulgaria"
) %>%
plotly::add_trace(
x = ~date,
y = ~Romania,
type = "scatter",
mode = "lines+markers",
name = "Romania"
) %>%
plotly::add_trace(
x = ~date,
y = ~`North Macedonia`,
type = "scatter",
mode = "lines+markers",
name = "N.Macedonia"
) %>%
plotly::add_trace(
x = ~date,
y = ~Serbia,
type = "scatter",
mode = "lines+markers",
name = "Serbia"
) %>%
plotly::add_trace(
x = ~date,
y = ~Greece,
type = "scatter",
mode = "lines+markers",
name = "Greece"
) %>%
plotly::layout(
title = "",
legend = list(x = 1, y = 0.9),
yaxis = list(title = "New confirmed cases"),
xaxis = list(title = "Date"),
hovermode = "compare",
margin = list(
b = 10,
t = 10,
pad = 2
)
)
```
Column {data-width=400}
-----------------------------------------------------------------------
### **Cases distribution by type**
```{r}
df_EU <- coronavirus %>%
dplyr::filter(country == "Bulgaria" |
country == "North Macedonia" |
country == "Romania" |
country == "Serbia" |
country == "Greece") %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total = sum(cases)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
dplyr::arrange(confirmed) %>%
dplyr::ungroup() %>%
dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
dplyr::mutate(country = trimws(country)) %>%
dplyr::mutate(country = factor(country, levels = country))
plotly::plot_ly(
data = df_EU,
x = ~country,
y = ~ confirmed,
type = "bar",
name = "Confirmed",
marker = list(color = active_color)
) %>%
plotly::add_trace(
y = ~death,
name = "Death",
marker = list(color = death_color)
) %>%
plotly::layout(
barmode = "stack",
yaxis = list(title = "Total cases"),
xaxis = list(title = ""),
hovermode = "compare",
margin = list(
b = 10,
t = 10,
pad = 2
)
)
```
Recovery / Death Ratio
=====================================
Column {data-width=400}
-----------------------------------------------------------------------
### **Recovery / Death Ratio**
```{r}
coronavirus %>%
dplyr::filter(country == "Bulgaria" | country == "Romania" | country == "Greece" | country == "Serbia" | country == "North Macedonia") %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total_cases = sum(cases)) %>%
tidyr::pivot_wider(names_from = type, values_from = total_cases) %>%
dplyr::arrange(- confirmed) %>%
dplyr::mutate(recover_rate = recovered / confirmed,
death_rate = death / confirmed) %>%
dplyr::mutate(recover_rate = dplyr::if_else(is.na(recover_rate), 0, recover_rate),
death_rate = dplyr::if_else(is.na(death_rate), 0, death_rate)) %>%
dplyr::ungroup() %>%
dplyr::mutate(confirmed_normal = as.numeric(confirmed) / max(as.numeric(confirmed))) %>%
plotly::plot_ly(y = ~ round(100 * recover_rate, 1),
x = ~ round(100 * death_rate, 1),
size = ~ log(confirmed),
sizes = c(5, 70),
type = 'scatter', mode = 'markers',
color = ~ country,
marker = list(sizemode = 'diameter' , opacity = 0.5),
hoverinfo = 'text',
text = ~paste("", country,
" Confirmed Cases: ", confirmed,
" Recovery Rate: ", paste(round(100 * recover_rate, 1), "%", sep = ""),
" Death Rate: ", paste(round(100 * death_rate, 1), "%", sep = ""))
) %>%
plotly::layout(title = "Recovery / Death Ratio",
yaxis = list(title = "Recovery Rate", ticksuffix = "%"),
xaxis = list(title = "Death Rate", ticksuffix = "%",
dtick = 1,
tick0 = 0),
hovermode = "compare")
```
World Map
=====================================
Column {data-width=400}
-----------------------------------------------------------------------
### **World map of cases** (*use + and - icons to zoom in/out*)
```{r}
# map tab added by Art Steinmetz
library(leaflet)
library(leafpop)
library(purrr)
cv_data_for_plot <- coronavirus %>%
# dplyr::filter(country == "Bulgaria") %>%
dplyr::filter(cases > 0) %>%
dplyr::group_by(country, province, lat, long, type) %>%
dplyr::summarise(cases = sum(cases)) %>%
dplyr::mutate(log_cases = 2 * log(cases)) %>%
dplyr::ungroup()
cv_data_for_plot.split <- cv_data_for_plot %>% split(cv_data_for_plot$type)
pal <- colorFactor(c("#4682B4", "#451208", "#02c48d"), domain = c("confirmed", "death", "recovered"))
map_object <- leaflet() %>% addProviderTiles(providers$Stamen.Toner)
names(cv_data_for_plot.split) %>%
purrr::walk(function(df) {
map_object <<- map_object %>%
addCircleMarkers(
data = cv_data_for_plot.split[[df]],
lng = ~long, lat = ~lat,
# label=~as.character(cases),
color = ~ pal(type),
stroke = FALSE,
fillOpacity = 0.6,
radius = ~log_cases,
popup = leafpop::popupTable(cv_data_for_plot.split[[df]],
feature.id = FALSE,
row.numbers = FALSE,
zcol = c("type", "cases", "country", "province")
),
group = df,
# clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
labelOptions = labelOptions(
noHide = F,
direction = "auto"
)
)
})
map_object %>%
addLayersControl(
overlayGroups = names(cv_data_for_plot.split),
options = layersControlOptions(collapsed = FALSE)
)
```
About
=======================================================================
**The Coronavirus Dashboard: the case of Bulgaria**
This [Coronavirus dashboard: the case of Bulgaria] provides an overview of the Novel Coronavirus (COVID-19 / SARS-CoV-2) epidemic for Bulgaria. This dashboard is built with R using the R Makrdown and flexdashboard framework and was adapted from this [dashboard](https://ramikrispin.github.io/coronavirus_dashboard/){target="_blank"} by Rami Krispin.
**Code**
The code behind this dashboard is available on [GitHub](https://github.com/AntoineSoetewey/coronavirus_dashboard){target="_blank"} courtesy of Antoine Soetewey.
**Packages**
* Dashboard interface - [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard/)
* Visualization - [plotly](https://plot.ly/r/)
* Data manipulation - [dplyr](https://dplyr.tidyverse.org/), [tidyr](https://tidyr.tidyverse.org/), and [purrr](https://purrr.tidyverse.org/)
* Mapping - [leaflet](https://rstudio.github.io/leaflet/) and [leafpop](https://github.com/r-spatial/leafpop)
**Data**
The input data for this dashboard is the dataset available from the [`{coronavirus}`](https://github.com/RamiKrispin/coronavirus){target="_blank"} R package.
The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/RamiKrispin/coronavirus-csv){target="_blank"}.